package com.mwcz.hot.work.controller;


import com.alibaba.fastjson.JSONObject;
import com.mwcz.hot.work.dao.CarDao;
import com.mwcz.hot.work.dao.WorkDao;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 车辆管理 前端控制器
 *
 * @author Mr.Bai
 * @since 2021-06-18
 */
@Slf4j
@RestController
@RequestMapping("api/admin/car")
@Api(tags = "车辆管理 -- 车辆管理")
public class CarController {
    @Autowired
    private CarDao carDao;

    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public Map<String,Object> selCar(@RequestBody JSONObject param){
        Map<String,Object> result = new HashMap<>();
        List<Map<String,Object>> list =carDao.selList(param);
        result.put("code",200);
        result.put("data",list);
        result.put("message","操作成功");
        return result;
    }

    @RequestMapping(value = "/freeList", method = RequestMethod.GET)
    public Map<String,Object> selFreeCar(){
        Map<String,Object> result = new HashMap<>();
        List<Map<String,Object>> list =carDao.selFreeList();
        result.put("code",200);
        result.put("data",list);
        result.put("message","操作成功");
        return result;
    }

    @RequestMapping(value = "/info", method = RequestMethod.GET)
    public Map<String,Object> selInfo(@RequestParam(defaultValue = "0") Integer id){
        Map<String,Object> result = new HashMap<>();
        Map<String,Object> info =carDao.selById(id);
        result.put("code",200);
        result.put("data",info);
        result.put("message","操作成功");
        return result;
    }

    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public Map<String,Object> saveSite(@RequestBody JSONObject param){
        Map<String,Object> result = new HashMap<String,Object>(3);
        Integer flag =carDao.saveCar(param);
        result.put("code",200);
        result.put("data",flag);
        result.put("message","操作成功");
        return result;
    }

    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public Map<String,Object> updateSite(@RequestParam Integer id,@RequestBody JSONObject param){
        Map<String,Object> result = new HashMap<String,Object>(3);
        Integer flag =carDao.updateCar(param);
        result.put("code",200);
        result.put("data",flag);
        result.put("message","操作成功");
        return result;
    }

    @RequestMapping(value = "/delete", method = RequestMethod.GET)
    public Map<String,Object> deleteSite(@RequestParam(defaultValue = "0") String type,@RequestParam(defaultValue = "0") String status){
        Map<String,Object> result = new HashMap<String,Object>(3);
//        List<Map<String,Object>> list =carDao.selList();
//        result.put("code",200);
//        result.put("data",list);
        result.put("message","操作成功");
        return result;
    }
}
